#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PLL; //
const ll N=1e5+5;
ll n,m;
vector<PLL> g[N];
ll fa[N][21],dep[N],dis[N];

void dfs(ll p,ll FA){
  fa[p][0]=FA;
  dep[p]=dep[FA]+1;
  for (ll i=1;i<=20;i++){
    fa[p][i]=fa[fa[p][i-1]][i-1];
  }
  for (auto son:g[p]){
    ll v=son.first,w=son.second;
    if (v==FA)continue;
    dis[v]=dis[p]+w;
    dfs(v,p);
  }              
}
ll LCA(ll u, ll v){
  if (dep[u]<dep[v])swap(u,v);
  for (ll i=20;i>=0;i--){
    if (dep[fa[u][i]]>=dep[v]){
      u=fa[u][i];
    }
  }
  if(u==v)return u;
  for (ll i=20;i>=0;i--){
    if (fa[u][i]!=fa[v][i]){
      u=fa[u][i];
      v=fa[v][i];
    }
  }
  return fa[u][0];
}
ll path_dis(ll u,ll v){
  return dis[u]+dis[v]-dis[LCA(u,v)];
}
int main(){
  cin>>n>>m;
  for (ll i=1;i<n;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    g[a].push_back({b,c});
    g[b].push_back({a,c});
  }
  dfs(1,0);
  vector<ll> init(m);
  ll ans=0;
  for (ll i=0;i<m;i++){
    cin>>init[i];
  }
  for (ll i=0;i<m-1;i++){
    ans+=path_dis(init[i],init[i+1]);
  }
  for (ll i=0;i<m;i++){
    ll sum=ans;
    if (i==0){
      sum-=path_dis(init[i],init[i+1]);
    }else if (i==m-1){
      sum-=path_dis(init[i-1],init[i]);
    }else{
      sum=sum-path_dis(init[i-1],init[i])-path_dis(init[i],init[i+1])+path_dis(init[i-1],init[i+1]);
    }
    cout<<sum<<" ";
  }
  return 0;
}
